﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;
using System.Windows;
using System.ComponentModel.Composition;
using Algoritmia.Problems.TravelingSalesPerson;

namespace Demos
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        [ImportMany]
        public ObservableCollection<IDemo> Demos { get; set; }

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Run()
        {
            Compose();
            listaLBX.ItemsSource = Demos;
        }

        private void Compose()
        {
            //var catalog = new DirectoryCatalog(@"\Demos");
            //catalog.Refresh();
            var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            var container = new CompositionContainer(catalog);
            container.ComposeParts(this);
        }

        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            Run();
        }

        private void OkClick(object sender, RoutedEventArgs e)
        {
            if (listaLBX.SelectedItem != null)
            {
                (listaLBX.SelectedItem as IDemo).Execute();
            }
        }
    }
}
